package in.smartride.server;

import in.smartride.dataInterface.DataHandler;
import in.smartride.dataInterface.RideOffer;
import in.smartride.dataInterface.RideRequest;

import java.util.List;

public class RideManager {
	DataHandler dataHandler;

	RideManager() {
		dataHandler = new DataHandler();
	}

	public List<RideOffer> processRideRequest(String from, String to,
			java.util.Date _time, String uId) {
		// call DAO function to get the array of objects of all ride
		// offers that match the from , to and time.
		List<RideOffer> Offers = dataHandler.retrieveRideOffer(from, to, _time);
		if (Offers == null || Offers.size()==0) {
			dataHandler.addRideRequest(from, to, _time, uId);
		}
		// delete the matched requests ??
		return Offers;
		// return the array in the form of a list to the server side script ,
		// null if it is of size 0.
	}

	public List<RideRequest> processRideOffer(String from, String to,
			java.util.Date _time, String uId) {
		// call servlet function to save this query

		// call servlet function to get the array of objects of all ride
		// requests that match the from , to and time.
		List<RideRequest> requests = dataHandler.retrieveRideRequest(from, to,
				_time);
		if (requests == null || requests.size()==0) {
			dataHandler.addRideOffer(from, to, _time, uId);
		}
		return requests;
		// delete saved requests ??
		// return the array in the form of a list to the server side script ,
		// null if it is
		// of size 0.
	}
	
	public void confirmRide(Long id, String request) {
	}
}
